#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.trigger.http;

import ${package}.api.model.request.UserReq;
import ${package}.api.model.response.ResultData;
import ${package}.api.model.response.UserRes;
import ${package}.domain.user.model.entity.UserEntity;
import ${package}.domain.user.service.IUserService;
import ${package}.trigger.http.mapstruct.request.UserReqConvert;
import ${package}.trigger.http.mapstruct.response.UserResConvert;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/api/user")
public class UserController {
    /**
     * 除非是简单参数如 Long userId，否则一律使用xxxReq接受参数；
     * 返回值统一使用ResultData包装，返回的data值的类型为xxxRes或者简单类型，结合实际决定
     */
    @Resource
    private IUserService userService;

    @PostMapping("")
    public ResultData<Boolean> addUser(@RequestBody UserReq userReq){
        userService.saveUser(UserReqConvert.INSTANCE.convertUserReqToUserEntity(userReq));
        return ResultData.success(Boolean.TRUE);
    }

    @GetMapping("")
    public ResultData<UserRes> getUser(@RequestParam Long userId){
        UserEntity userEntity = userService.getUserByUserId(userId);
        UserRes userRes = UserResConvert.INSTANCE.convertUserEntityToUserReq(userEntity);
        return ResultData.success(userRes);
    }

    @PutMapping("")
    public ResultData<Boolean> updateUser(@RequestBody UserReq userReq){
        userService.updateUser(UserReqConvert.INSTANCE.convertUserReqToUserEntity(userReq));
        return ResultData.success(true);
    }

    @DeleteMapping("")
    public ResultData<Boolean> deleterUsers(@RequestParam List<Long> userIds){
        userService.deleteUser(userIds);
        return ResultData.success(Boolean.TRUE);
    }

}